package org.dfl.plugin.editor.model;

import java.util.ArrayList;
import java.util.Collection;

import org.dfl.core.model.OutputPlace;
import org.dfl.core.model.Place;
import org.dfl.core.model.XMLLoaderException;
import org.dfl.messages.Messages;
import org.dfl.plugin.editor.markers.ModelMarkersContainer;
import org.dfl.plugin.editor.markers.ModelProblem;
import org.jdom.Element;

/**
 * editor's model element that represents an output place
 * @author Piotr Wlodarczyk
 *
 */
@SuppressWarnings("serial")
public class OutputPlaceModelElement extends PlaceModelElement {
	public OutputPlaceModelElement(){
		super();
	}
	
	public OutputPlaceModelElement(Element elem) throws XMLLoaderException {
		super(elem);
	}

	@Override
	protected void addSourceConnection(ConnectionModelElement conn) throws Exception{
		throw new Exception(Messages.OutputPlaceModelElement_errorConnect);
	}
	
	@Override
	protected Place getDefaultPlace() {
		return new OutputPlace();
	}
	
	@Override
	public String getLabelText() {
		return Messages.OutputPlaceModelElement_prefix+super.getLabelText();
	}
	
	@Override
	public Collection<ModelProblem> getProblems() {
		Collection<ModelProblem> problems = new ArrayList<ModelProblem>();
		
		// check inputs
		if(getPlace().getInputEdges().isEmpty()){
			problems.add(ModelMarkersContainer.createError(Messages.OutputPlaceModelElement_problemNoConnection ,Messages.OutputPlaceModelElement_name, getPlace().getId()));
		}
		
		return problems;
	}
	
	@Override
	public OutputPlace getPlace() {
		return (OutputPlace) super.getPlace();
	}
	
	public boolean isConnected(){
		return !getPlace().getInputEdges().isEmpty();
	}
}
